<?php

declare(strict_types=1);

$registry = [
    'protocol' => 'nacos',
    'address' => 'http://'.env('NACOS_HOST').':'.(int)env('NACOS_PORT'),
];

$consumers = [
    [
        'name' => 'AuthAccountService',
    ],
    [
        'name' => 'StorageService',
    ]
];

$userCenterNode = [
    ['host' => '114.116.230.53', 'port' => 8504],
];

$storageNode = [
    ['host' => '114.116.230.53', 'port' => 8507],
];


$appEnv = env('APP_ENV');
foreach ($consumers as &$consumer) {
    if ($appEnv == 'dev') {
        if (in_array($consumer['name'], array('AuthAccountService'))) {
            $consumer['nodes'] = $userCenterNode;
        } elseif (in_array($consumer['name'], array('StorageService'))) {
            $consumer['nodes'] = $storageNode;
        }
    } else {
        $consumer['registry'] = $registry;
    }
}

return [
    'enable' => [
        // 开启服务发现
        'discovery' => true,
        // 开启服务注册
        'node' => true,
    ],
    // 服务消费者相关配置
    'consumers' => $consumers,
    // 服务提供者相关配置
    'providers' => [],
    // 服务驱动相关配置
    'drivers' => [
        'nacos' => [
            // nacos server url like https://nacos.hyperf.io, Priority is higher than host:port
            // 'url' => '',
            // The nacos host info
            'host' => env('NACOS_HOST'),
            'port' => (int)env('NACOS_PORT'),
            // The nacos account info
            'username' => env('NACOS_USERNAME'),
            'password' => env('NACOS_PASSWORD'),
            'guzzle' => [
                'config' => null,
            ],
            'group_name' => 'rpc',
            'namespace_id' => '',
            'heartbeat' => 20,
        ],
    ],
];
